<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <script src="vue.js"></script>
  </head>
  <body>
    <div id="root">
      <counter ref="one" @change="handleClick"></counter>
      <counter ref="two" @change="handleClick"></counter>
      <div>{{ count }}</div>
    </div>

    <script>
      Vue.component('counter', {
        template: '<div @click="handleClick">{{number}}</div>',
        data() {
          return {
            number: 0
          };
        },
        methods: {
          handleClick: function() {
            this.number++;
            this.$emit('change');
          }
        }
      });
      new Vue({
        el: '#root',
        data: {
          count: 0
        },
        methods: {
          handleClick: function() {
            //子组件引用
            this.count = this.$refs.one.number + this.$refs.two.number;
          }
        }
      });
    </script>
  </body>
</html>
